package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysUsertype;
import com.ruoyi.system.service.ISysUsertypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-09-30
 */
@RestController
@RequestMapping("/usertype")
public class SysUsertypeController extends BaseController
{
    @Autowired
    private ISysUsertypeService sysUsertypeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:usertype:list")
    @GetMapping("/list")
    public TableDataInfo list(SysUsertype sysUsertype)
    {
        startPage();
        List<SysUsertype> list = sysUsertypeService.selectSysUsertypeList(sysUsertype);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:usertype:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUsertype sysUsertype)
    {
        List<SysUsertype> list = sysUsertypeService.selectSysUsertypeList(sysUsertype);
        ExcelUtil<SysUsertype> util = new ExcelUtil<SysUsertype>(SysUsertype.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("system:usertype:query")
    @GetMapping(value = "/{usertypeId}")
    public AjaxResult getInfo(@PathVariable("usertypeId") Long usertypeId)
    {
        return AjaxResult.success(sysUsertypeService.selectSysUsertypeByUsertypeId(usertypeId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("system:usertype:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUsertype sysUsertype)
    {
        return toAjax(sysUsertypeService.insertSysUsertype(sysUsertype));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:usertype:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUsertype sysUsertype)
    {
        return toAjax(sysUsertypeService.updateSysUsertype(sysUsertype));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:usertype:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{usertypeIds}")
    public AjaxResult remove(@PathVariable Long[] usertypeIds)
    {
        return toAjax(sysUsertypeService.deleteSysUsertypeByUsertypeIds(usertypeIds));
    }
}
